package com.i2bt.adapter;

import com.i2bt.R;
import com.i2bt.app.BaseActivity;
import com.i2bt.bean.FriendInfoBean;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class FriendAddListAdapter extends BaseAdapter {
	
	private List<FriendInfoBean> friendSearchInfoList;		//搜索结果列表
	
	private BaseActivity activity;
	
	public FriendAddListAdapter(BaseActivity activity, 
			List<FriendInfoBean> friendSearchInfoList) {
		this.activity = activity;
		this.friendSearchInfoList = friendSearchInfoList;
		if (this.friendSearchInfoList == null) {
			friendSearchInfoList = new ArrayList<FriendInfoBean>();
		}
	}

	@Override
	public int getCount() {
		return friendSearchInfoList.size();
	}

	@Override
	public Object getItem(int position) {
		return friendSearchInfoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder =  null;
		if (convertView == null) {
			convertView = LayoutInflater.from(activity).inflate(
					R.layout.item_friend_search_list, null, false);
			
			holder = new ViewHolder();
			
			holder.friendName = (TextView) convertView.findViewById(R.id.friend_item_name);
			
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.friendName.setText(friendSearchInfoList.
				get(position).getFriendName());
		
		return convertView;
	}
	
	private class ViewHolder {
		
		ImageView friendImage;
		
		TextView friendName;
		
		Button friendConcern;
	}
	
	public void setData(List<FriendInfoBean> friendSearchInfoList) {
		this.friendSearchInfoList = friendSearchInfoList;
	}

}
